<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Simple Router for Vue</title>
  <script src="./node_modules/vue/dist/vue.js"></script>
</head>
<body>
  <div id="app">
    <component :is="view"></component>
  </div>
  <script>
    var vm = new Vue({
      el: '#app',
      components: {
        'hello': {
          template: '<h1>Hello <a href="#world">world</a></h1>'
        },
        'world': {
          template: '<h1>World <a href="#hello">hello</a></h1>'
        },
        'error404': {
          template: '<h1>404</h1>'
        }
      },
      data: {
        view: 'hello'
      }
    })

    function showCurrentView() {
      var hash = location.hash.replace('#', '')
      if (hash) {
        if (vm.$options.components[hash]) {
          vm.$data.view = hash
        } else {
          vm.$data.view = 'error404'
        }
      } else {
        vm.$data.view = 'hello'
      }
    }

    window.addEventListener('hashchange', function () {
      showCurrentView()
    }, false)

    showCurrentView()
  </script>
</body>
</html>